package com.fr.cell.core.date;

import com.fr.base.BaseUtils;
import java.awt.Dimension;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.Icon;
import javax.swing.JLabel;

public class JDayLabel extends JLabel
{
  private static Icon todayIcon = BaseUtils.readIcon("/com/fr/cell/core/date/today.gif");
  private Date date;
  private Icon currentIcon;
  final SimpleDateFormat dateFormat;
  final SimpleDateFormat dayFormat;

  public JDayLabel(Date paramDate)
  {
    this(paramDate, true);
  }

  public JDayLabel(Date paramDate, boolean paramBoolean)
  {
    this.date = null;
    this.currentIcon = null;
    this.dateFormat = new SimpleDateFormat("yyyy/MM/dd");
    this.dayFormat = new SimpleDateFormat("d");
    setPreferredSize(new Dimension(40, 20));
    setToolTipText(this.dateFormat.format(paramDate));
    this.date = paramDate;
    if (paramBoolean)
    {
      setHorizontalAlignment(0);
      setText(this.dayFormat.format(paramDate));
      Date localDate = new Date();
      if (this.dateFormat.format(paramDate).equals(this.dateFormat.format(localDate)))
        this.currentIcon = todayIcon;
    }
    else
    {
      setText("Today:" + this.dateFormat.format(new Date()));
      setIcon(todayIcon);
      setHorizontalAlignment(2);
    }
  }

  public Date getDate()
  {
    return this.date;
  }

  public void setDate(Date paramDate)
  {
    this.date = paramDate;
  }

  public void paint(Graphics paramGraphics)
  {
    super.paint(paramGraphics);
    if ((this.currentIcon != null) && (isEnabled()))
    {
      int i = (getWidth() - this.currentIcon.getIconWidth()) / 2;
      int j = (getHeight() - this.currentIcon.getIconHeight()) / 2;
      this.currentIcon.paintIcon(this, paramGraphics, i, j);
    }
  }
}